﻿namespace UnityEditor
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using UnityEditorInternal;
    using UnityEngine;

    internal class LightmappingWindow : EditorWindow, ICanHazCustomMenu
    {
        [CompilerGenerated]
        private static Func<string, string> <>f__am$cache26;
        private const string kBakeModeKey = "LightmapEditor.BakeMode";
        private const string kBeastSettingsFileName = "BeastSettings.xml";
        private GUIContent[] kBouncesStrings;
        private int[] kBouncesValues;
        private GUIContent[] kModeStrings;
        private int[] kModeValues;
        private GUIContent[] kQualityStrings;
        private int[] kQualityValues;
        private GUIContent[] kShadowTypeStrings;
        private int[] kShadowTypeValues;
        private GUIContent[] kTerrainLightmapSizeStrings;
        private int[] kTerrainLightmapSizeValues;
        private AnimValueManager m_Anims;
        private float m_BakeStartTime;
        private bool m_IncorrectProbePositions;
        private int m_LastAmountOfLights;
        private string m_LastBakeTimeString;
        private readonly LightProbeGUI m_LightProbeEditor;
        private Mode m_Mode;
        private float m_OldQualitySettingsShadowDistance;
        private float m_OldResolution;
        private PreviewResizer m_PreviewResizer;
        private bool m_ProbePositionsChanged;
        private Vector2 m_ScrollPosition;
        private Vector2 m_ScrollPositionLightmaps;
        private Vector2 m_ScrollPositionMaps;
        private int m_SelectedLightmap;
        private float m_ShadowDistance;
        private AnimBool m_ShowAO;
        private AnimBool m_ShowAreaLight;
        private bool m_ShowAtlas;
        private AnimBool m_ShowClampedSize;
        private AnimBool m_ShowColorSpaceWarning;
        private AnimBool m_ShowDualOptions;
        private AnimBool m_ShowFinalGather;
        private AnimBool m_ShowShadowAngleOrSize;
        private AnimBool m_ShowShadowOptions;
        private static bool s_IsVisible;
        private static LightmappingWindow s_LightmappingWindow;
        private static Styles s_Styles;

        public LightmappingWindow()
        {
            int[] numArray1 = new int[3];
            numArray1[1] = 1;
            numArray1[2] = 2;
            this.kModeValues = numArray1;
            this.kModeStrings = new GUIContent[] { new GUIContent("Single Lightmaps"), new GUIContent("Dual Lightmaps"), new GUIContent("Directional Lightmaps") };
            this.kBouncesStrings = new GUIContent[] { new GUIContent("0"), new GUIContent("1"), new GUIContent("2"), new GUIContent("3"), new GUIContent("4") };
            this.kBouncesValues = new int[] { 0, 1, 2, 3, 4 };
            this.kQualityStrings = new GUIContent[] { new GUIContent("High"), new GUIContent("Low") };
            int[] numArray2 = new int[2];
            numArray2[1] = 1;
            this.kQualityValues = numArray2;
            this.kShadowTypeStrings = new GUIContent[] { new GUIContent("Off"), new GUIContent("On (Realtime: Hard Shadows)"), new GUIContent("On (Realtime: Soft Shadows)") };
            int[] numArray3 = new int[3];
            numArray3[1] = 1;
            numArray3[2] = 2;
            this.kShadowTypeValues = numArray3;
            this.kTerrainLightmapSizeStrings = new GUIContent[] { new GUIContent("0"), new GUIContent("32"), new GUIContent("64"), new GUIContent("128"), new GUIContent("256"), new GUIContent("512"), new GUIContent("1024"), new GUIContent("2048"), new GUIContent("4096") };
            this.kTerrainLightmapSizeValues = new int[] { 0, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000 };
            this.m_LightProbeEditor = new LightProbeGUI();
            this.m_ScrollPosition = Vector2.zero;
            this.m_ScrollPositionLightmaps = Vector2.zero;
            this.m_ScrollPositionMaps = Vector2.zero;
            this.m_OldResolution = -1f;
            this.m_SelectedLightmap = -1;
            this.m_BakeStartTime = -1f;
            this.m_LastBakeTimeString = string.Empty;
            this.m_Anims = new AnimValueManager();
            this.m_ShowDualOptions = new AnimBool();
            this.m_ShowFinalGather = new AnimBool();
            this.m_ShowShadowOptions = new AnimBool();
            this.m_ShowShadowAngleOrSize = new AnimBool();
            this.m_ShowAO = new AnimBool();
            this.m_ShowClampedSize = new AnimBool();
            this.m_ShowColorSpaceWarning = new AnimBool();
            this.m_ShowAreaLight = new AnimBool();
            this.m_PreviewResizer = new PreviewResizer();
            this.m_ProbePositionsChanged = true;
            this.m_OldQualitySettingsShadowDistance = -1f;
            this.m_ShadowDistance = -1f;
        }

        public virtual void AddItemsToMenu(GenericMenu menu)
        {
            menu.AddItem(new GUIContent("Generate Beast settings file"), false, new GenericMenu.MenuFunction(this.GenerateBeastSettingsFile));
        }

        private bool BakeButton(params GUILayoutOption[] options)
        {
            GUIContent content = EditorGUIUtility.TempContent(ObjectNames.NicifyVariableName(this.bakeMode.ToString()));
            Rect position = GUILayoutUtility.GetRect(content, s_Styles.dropDownButton, options);
            Rect rect2 = position;
            rect2.xMin = rect2.xMax - 20f;
            if ((Event.current.type != EventType.MouseDown) || !rect2.Contains(Event.current.mousePosition))
            {
                return GUI.Button(position, content, s_Styles.dropDownButton);
            }
            GenericMenu menu = new GenericMenu();
            string[] names = Enum.GetNames(typeof(BakeMode));
            int index = Array.IndexOf<string>(names, Enum.GetName(typeof(BakeMode), this.bakeMode));
            int num2 = 0;
            if (<>f__am$cache26 == null)
            {
                <>f__am$cache26 = x => ObjectNames.NicifyVariableName(x);
            }
            IEnumerator<string> enumerator = Enumerable.Select<string, string>(names, <>f__am$cache26).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    string current = enumerator.Current;
                    menu.AddItem(new GUIContent(current), num2 == index, new GenericMenu.MenuFunction2(this.BakeDropDownCallback), num2++);
                }
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
            menu.DropDown(position);
            Event.current.Use();
            return false;
        }

        private void BakeDropDownCallback(object data)
        {
            this.bakeMode = (BakeMode) ((int) data);
            this.DoBake();
        }

        private void BakeSettings()
        {
            SerializedObject obj2 = new SerializedObject(LightmapEditorSettings.GetLightmapSettings());
            SerializedProperty property = obj2.FindProperty("m_LightmapsMode");
            SerializedProperty property2 = obj2.FindProperty("m_UseDualLightmapsInForward");
            SerializedProperty property3 = obj2.FindProperty("m_LightmapEditorSettings.m_SkyLightColor");
            SerializedProperty property4 = obj2.FindProperty("m_LightmapEditorSettings.m_SkyLightIntensity");
            SerializedProperty property5 = obj2.FindProperty("m_LightmapEditorSettings.m_Bounces");
            SerializedProperty property6 = obj2.FindProperty("m_LightmapEditorSettings.m_BounceBoost");
            SerializedProperty property7 = obj2.FindProperty("m_LightmapEditorSettings.m_BounceIntensity");
            SerializedProperty property8 = obj2.FindProperty("m_LightmapEditorSettings.m_Quality");
            SerializedProperty property9 = obj2.FindProperty("m_LightmapEditorSettings.m_FinalGatherRays");
            SerializedProperty property10 = obj2.FindProperty("m_LightmapEditorSettings.m_FinalGatherContrastThreshold");
            SerializedProperty property11 = obj2.FindProperty("m_LightmapEditorSettings.m_FinalGatherGradientThreshold");
            SerializedProperty property12 = obj2.FindProperty("m_LightmapEditorSettings.m_FinalGatherInterpolationPoints");
            SerializedProperty property13 = obj2.FindProperty("m_LightmapEditorSettings.m_AOAmount");
            SerializedProperty property14 = obj2.FindProperty("m_LightmapEditorSettings.m_AOMaxDistance");
            SerializedProperty property15 = obj2.FindProperty("m_LightmapEditorSettings.m_AOContrast");
            SerializedProperty property16 = obj2.FindProperty("m_LightmapEditorSettings.m_LockAtlas");
            SerializedProperty property17 = obj2.FindProperty("m_LightmapEditorSettings.m_Resolution");
            SerializedProperty property18 = obj2.FindProperty("m_LightmapEditorSettings.m_Padding");
            SerializedProperty property19 = obj2.FindProperty("m_LightmapEditorSettings.m_LODSurfaceMappingDistance");
            bool flag = this.BeastSettingsFileOverride();
            EditorGUILayout.IntPopup(property, this.kModeStrings, this.kModeValues, s_Styles.Mode, new GUILayoutOption[0]);
            this.m_ShowDualOptions.target = LightmapSettings.lightmapsMode == LightmapsMode.Dual;
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowDualOptions.faded))
            {
                EditorGUILayout.PropertyField(property2, s_Styles.UseDualInForward, new GUILayoutOption[0]);
            }
            EditorGUILayout.EndFadeGroup();
            GUILayout.Space(5f);
            GUI.enabled = !flag;
            int intValue = property8.intValue;
            EditorGUILayout.IntPopup(property8, this.kQualityStrings, this.kQualityValues, s_Styles.Quality, new GUILayoutOption[0]);
            if (property8.intValue != intValue)
            {
                if (property8.intValue == 0)
                {
                    property9.intValue = 0x3e8;
                    property10.floatValue = 0.05f;
                }
                else
                {
                    property9.intValue = 200;
                    property10.floatValue = 0.1f;
                }
            }
            GUILayout.Space(5f);
            if (InternalEditorUtility.HasPro())
            {
                EditorGUILayout.IntPopup(property5, this.kBouncesStrings, this.kBouncesValues, s_Styles.Bounces, new GUILayoutOption[0]);
            }
            else
            {
                bool enabled = GUI.enabled;
                GUI.enabled = false;
                string[] displayedOptions = new string[] { "0" };
                EditorGUILayout.IntPopup(s_Styles.Bounces.text, 0, displayedOptions, this.kBouncesValues, new GUILayoutOption[0]);
                GUI.enabled = enabled;
            }
            this.m_ShowFinalGather.target = (property5.intValue > 0) && InternalEditorUtility.HasPro();
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowFinalGather.faded))
            {
                EditorGUILayout.PropertyField(property3, s_Styles.SkyLightColor, new GUILayoutOption[0]);
                EditorGUILayout.PropertyField(property4, s_Styles.SkyLightIntensity, new GUILayoutOption[0]);
                if (property4.floatValue < 0f)
                {
                    property4.floatValue = 0f;
                }
                EditorGUILayout.Slider(property6, 0f, 4f, s_Styles.BounceBoost, new GUILayoutOption[0]);
                EditorGUILayout.Slider(property7, 0f, 5f, s_Styles.BounceIntensity, new GUILayoutOption[0]);
                EditorGUILayout.PropertyField(property9, s_Styles.FinalGatherRays, new GUILayoutOption[0]);
                if (property9.intValue < 1)
                {
                    property9.intValue = 1;
                }
                EditorGUILayout.Slider(property10, 0f, 0.5f, s_Styles.FinalGatherContrastThreshold, new GUILayoutOption[0]);
                EditorGUILayout.Slider(property11, 0f, 1f, s_Styles.FinalGatherGradientThreshold, new GUILayoutOption[0]);
                EditorGUILayout.IntSlider(property12, 15, 30, s_Styles.FinalGatherInterpolationPoints, new GUILayoutOption[0]);
            }
            EditorGUILayout.EndFadeGroup();
            GUI.enabled = true;
            GUILayout.Space(5f);
            EditorGUILayout.Slider(property13, 0f, 1f, s_Styles.AO, new GUILayoutOption[0]);
            this.m_ShowAO.target = property13.floatValue > 0f;
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowAO.faded))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(property14, s_Styles.AOMaxDistance, new GUILayoutOption[0]);
                if (property14.floatValue < 0f)
                {
                    property14.floatValue = 0f;
                }
                EditorGUILayout.Slider(property15, 0f, 2f, s_Styles.AOContrast, new GUILayoutOption[0]);
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndFadeGroup();
            GUILayout.Space(5f);
            EditorGUILayout.PropertyField(property19, s_Styles.LODSurfaceDistance, new GUILayoutOption[0]);
            GUILayout.Space(20f);
            EditorGUILayout.PropertyField(property16, s_Styles.LockAtlas, new GUILayoutOption[0]);
            GUI.enabled = !property16.boolValue;
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(property17, s_Styles.Resolution, new GUILayoutOption[0]);
            if (property17.floatValue != this.m_OldResolution)
            {
                property17.floatValue = (property17.floatValue <= 0f) ? 0f : property17.floatValue;
                SceneView.RepaintAll();
                this.m_OldResolution = property17.floatValue;
            }
            GUILayout.Label(" texels per world unit", s_Styles.labelStyle, new GUILayoutOption[0]);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(property18, s_Styles.Padding, new GUILayoutOption[0]);
            GUILayout.Label(" texels", s_Styles.labelStyle, new GUILayoutOption[0]);
            GUILayout.EndHorizontal();
            GUI.enabled = true;
            obj2.ApplyModifiedProperties();
        }

        private bool BeastSettingsFileOverride()
        {
            string path = this.GetLightmapAssetsPath() + "/BeastSettings.xml";
            if (!File.Exists(path))
            {
                return false;
            }
            GUILayout.Space(5f);
            GUILayout.BeginVertical(GUI.skin.box, new GUILayoutOption[0]);
            GUILayout.Label("Bake settings will be overridden by BeastSettings.xml", s_Styles.labelStyle, new GUILayoutOption[0]);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(false) };
            if (GUILayout.Button("Open", options))
            {
                AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(path));
            }
            GUILayout.EndVertical();
            GUILayout.Space(5f);
            return true;
        }

        private void Buttons()
        {
            float width = 120f;
            bool disabled = (LightmapSettings.lightmapsMode == LightmapsMode.Directional) && !InternalEditorUtility.HasPro();
            if (disabled)
            {
                EditorGUILayout.HelpBox(s_Styles.DirectionalLightmapsProOnly.text, MessageType.Warning);
            }
            EditorGUI.BeginDisabledGroup(disabled);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(width) };
            if (GUILayout.Button("Clear", options))
            {
                Lightmapping.Clear();
                Analytics.Track("/LightMapper/Clear");
            }
            if (!Lightmapping.isRunning)
            {
                GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.Width(width) };
                if (this.BakeButton(optionArray2))
                {
                    this.DoBake();
                    GUIUtility.ExitGUI();
                }
            }
            else
            {
                GUILayoutOption[] optionArray3 = new GUILayoutOption[] { GUILayout.Width(width) };
                if (GUILayout.Button("Cancel", optionArray3))
                {
                    Lightmapping.Cancel();
                    this.m_BakeStartTime = -1f;
                    Analytics.Track("/LightMapper/Cancel");
                }
            }
            GUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();
        }

        private void Compress()
        {
            bool flag = true;
            LightmapData[] lightmaps = LightmapSettings.lightmaps;
            Texture2D assetObject = null;
            foreach (LightmapData data in lightmaps)
            {
                if (data.lightmapFar != null)
                {
                    assetObject = data.lightmapFar;
                    break;
                }
                if (data.lightmapNear != null)
                {
                    assetObject = data.lightmapNear;
                    break;
                }
            }
            if (assetObject != null)
            {
                TextureImporter atPath = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(assetObject)) as TextureImporter;
                if (atPath != null)
                {
                    flag = atPath.textureFormat == TextureImporterFormat.AutomaticCompressed;
                }
            }
            bool flag2 = EditorGUILayout.Toggle(s_Styles.TextureCompression, flag, new GUILayoutOption[0]);
            if (flag2 != flag)
            {
                Selection.objects = new UnityEngine.Object[0];
                foreach (LightmapData data2 in lightmaps)
                {
                    string assetPath = AssetDatabase.GetAssetPath(data2.lightmapFar);
                    TextureImporter importer2 = AssetImporter.GetAtPath(assetPath) as TextureImporter;
                    if (importer2 != null)
                    {
                        importer2.textureFormat = !flag2 ? TextureImporterFormat.AutomaticTruecolor : TextureImporterFormat.AutomaticCompressed;
                        AssetDatabase.ImportAsset(assetPath);
                    }
                    string path = AssetDatabase.GetAssetPath(data2.lightmapNear);
                    TextureImporter importer3 = AssetImporter.GetAtPath(path) as TextureImporter;
                    if (importer3 != null)
                    {
                        importer3.textureFormat = !flag2 ? TextureImporterFormat.AutomaticTruecolor : TextureImporterFormat.AutomaticCompressed;
                        AssetDatabase.ImportAsset(path);
                    }
                }
            }
        }

        [UnityEditor.MenuItem("Window/Lightmapping", false, 0x832)]
        private static void CreateLightmapEditor()
        {
            LightmappingWindow window = EditorWindow.GetWindow<LightmappingWindow>();
            window.title = EditorGUIUtility.TextContent("LightmapEditor.WindowTitle").text;
            window.minSize = new Vector2(300f, 360f);
            window.Show();
        }

        private void DisplayControls(UnityEngine.Object target, SceneView sceneView)
        {
            EditorGUIUtility.LookLikeControls(110f);
            bool useLightmaps = LightmapVisualization.useLightmaps;
            if (useLightmaps != EditorGUILayout.Toggle(EditorGUIUtility.TextContent("LightmapEditor.UseLightmaps"), useLightmaps, new GUILayoutOption[0]))
            {
                LightmapVisualization.useLightmaps = !useLightmaps;
                RepaintSceneAndGameViews();
            }
            float num = Mathf.Max(EditorGUILayout.FloatField(EditorGUIUtility.TextContent("LightmapEditor.ShadowDistance"), this.m_ShadowDistance, new GUILayoutOption[0]), 0f);
            if (num != this.m_ShadowDistance)
            {
                this.m_ShadowDistance = num;
                LightmapVisualization.shadowDistance = this.m_ShadowDistance;
                RepaintSceneAndGameViews();
            }
            if (sceneView != null)
            {
                DrawCameraMode renderMode = sceneView.renderMode;
                bool flag2 = EditorGUILayout.Toggle(EditorGUIUtility.TextContent("LightmapEditor.DisplayControls.VisualiseResolution"), renderMode == DrawCameraMode.LightmapResolution, new GUILayoutOption[0]);
                if (flag2 && (renderMode != DrawCameraMode.LightmapResolution))
                {
                    sceneView.renderMode = DrawCameraMode.LightmapResolution;
                    sceneView.Repaint();
                }
                else if (!flag2 && (renderMode == DrawCameraMode.LightmapResolution))
                {
                    sceneView.renderMode = DrawCameraMode.Textured;
                    sceneView.Repaint();
                }
                this.m_LightProbeEditor.DisplayControls(sceneView);
            }
            else
            {
                bool enabled = GUI.enabled;
                GUI.enabled = false;
                EditorGUILayout.Toggle(EditorGUIUtility.TextContent("LightmapEditor.DisplayControls.VisualiseResolution"), false, new GUILayoutOption[0]);
                GUI.enabled = enabled;
            }
        }

        private void DoBake()
        {
            LightmapsMode lightmapsMode = LightmapSettings.lightmapsMode;
            Analytics.Track("/LightMapper/Start");
            Analytics.Event("LightMapper", "Mode", lightmapsMode.ToString(), 1);
            this.MarkStartTime();
            switch (this.bakeMode)
            {
                case BakeMode.BakeScene:
                    Analytics.Event("LightMapper", "Button", "BakeScene", 1);
                    Lightmapping.BakeAsync();
                    break;

                case BakeMode.BakeSelected:
                    Analytics.Event("LightMapper", "Button", "BakeSelected", 1);
                    Lightmapping.BakeSelectedAsync();
                    break;

                case BakeMode.BakeProbes:
                    Analytics.Event("LightMapper", "Button", "BakeProbes", 1);
                    Lightmapping.BakeLightProbesOnlyAsync();
                    break;
            }
        }

        private void GenerateBeastSettingsFile()
        {
            string lightmapAssetsPath = this.GetLightmapAssetsPath();
            string path = lightmapAssetsPath + "/BeastSettings.xml";
            if (lightmapAssetsPath.Length == 0)
            {
                Debug.LogWarning("Scene hasn't been saved yet, can't generate settings file.");
            }
            else if (File.Exists(path))
            {
                Debug.LogWarning("Beast settings file already exists for this scene.");
            }
            else
            {
                Directory.CreateDirectory(lightmapAssetsPath);
                AssetDatabase.ImportAsset(lightmapAssetsPath);
                FileUtil.CopyFileOrDirectory(EditorApplication.applicationContentsPath + "/Resources/BeastSettings.xml", path);
                AssetDatabase.ImportAsset(path);
            }
        }

        private string GetLightmapAssetsPath()
        {
            string currentScene = EditorApplication.currentScene;
            return currentScene.Substring(0, Mathf.Max(0, currentScene.Length - 6));
        }

        private bool HasNormals(UnityEngine.Renderer renderer)
        {
            Mesh sharedMesh = null;
            if (renderer is MeshRenderer)
            {
                sharedMesh = renderer.GetComponent<MeshFilter>().sharedMesh;
            }
            else if (renderer is SkinnedMeshRenderer)
            {
                sharedMesh = (renderer as SkinnedMeshRenderer).sharedMesh;
            }
            return InternalMeshUtil.HasNormals(sharedMesh);
        }

        private static void Header(ref Rect rect, float headerHeight, float headerLeftMargin, float maxLightmaps, LightmapsMode lightmapsMode)
        {
            Rect position = GUILayoutUtility.GetRect(rect.width, headerHeight);
            position.width = rect.width / maxLightmaps;
            position.y -= rect.height;
            rect.y += headerHeight;
            position.x += headerLeftMargin;
            if (lightmapsMode == LightmapsMode.Directional)
            {
                EditorGUI.DropShadowLabel(position, "color");
                position.x += position.width;
                EditorGUI.DropShadowLabel(position, "scale");
            }
            else
            {
                EditorGUI.DropShadowLabel(position, "far");
                position.x += position.width;
                EditorGUI.DropShadowLabel(position, "near");
            }
        }

        private Texture2D LightmapField(Texture2D lightmap, int index)
        {
            Rect rect = GUILayoutUtility.GetRect(100f, 100f, EditorStyles.objectField);
            this.MenuSelectLightmapUsers(rect, index);
            Texture2D textured = EditorGUI.ObjectField(rect, lightmap, typeof(Texture2D), false) as Texture2D;
            if ((index == this.m_SelectedLightmap) && (Event.current.type == EventType.Repaint))
            {
                s_Styles.selectedLightmapHighlight.Draw(rect, false, false, false, false);
            }
            return textured;
        }

        private static void LightmappingDone()
        {
            if (s_LightmappingWindow != null)
            {
                s_LightmappingWindow.MarkEndTime();
                s_LightmappingWindow.Repaint();
            }
            Analytics.Track("/LightMapper/Created");
        }

        private void Lightmaps(Rect r)
        {
            bool flag = true;
            GUI.Box(r, string.Empty, "PreBackground");
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Height(r.height) };
            this.m_ScrollPositionLightmaps = EditorGUILayout.BeginScrollView(this.m_ScrollPositionLightmaps, options);
            int lightmapIndex = 0;
            LightmapsMode lightmapsMode = LightmapSettings.lightmapsMode;
            float maxLightmaps = 2f;
            foreach (LightmapData data in LightmapSettings.lightmaps)
            {
                if (data.lightmapFar == null)
                {
                    lightmapIndex++;
                }
                else
                {
                    GUILayoutOption[] optionArray = new GUILayoutOption[] { GUILayout.MaxWidth(data.lightmapFar.width * maxLightmaps), GUILayout.MaxHeight((float) data.lightmapFar.height) };
                    Rect aspectRect = GUILayoutUtility.GetAspectRect((data.lightmapFar.width * maxLightmaps) / ((float) data.lightmapFar.height), optionArray);
                    if (flag)
                    {
                        Header(ref aspectRect, 20f, 6f, maxLightmaps, lightmapsMode);
                        flag = false;
                    }
                    aspectRect.width /= maxLightmaps;
                    EditorGUI.DrawPreviewTexture(aspectRect, data.lightmapFar);
                    this.MenuSelectLightmapUsers(aspectRect, lightmapIndex);
                    if (data.lightmapNear != null)
                    {
                        aspectRect.x += aspectRect.width;
                        EditorGUI.DrawPreviewTexture(aspectRect, data.lightmapNear);
                        this.MenuSelectLightmapUsers(aspectRect, lightmapIndex);
                    }
                    lightmapIndex++;
                }
            }
            EditorGUILayout.EndScrollView();
        }

        private float LightmapScaleGUI(SerializedObject so, UnityEngine.Renderer[] renderers)
        {
            float lightmapLODLevelScale = LightmapVisualization.GetLightmapLODLevelScale(renderers[0]);
            for (int i = 1; i < renderers.Length; i++)
            {
                if (!Mathf.Approximately(lightmapLODLevelScale, LightmapVisualization.GetLightmapLODLevelScale(renderers[i])))
                {
                    lightmapLODLevelScale = 1f;
                }
            }
            SerializedProperty property = so.FindProperty("m_ScaleInLightmap");
            float num3 = lightmapLODLevelScale * property.floatValue;
            Rect controlRect = EditorGUILayout.GetControlRect(new GUILayoutOption[0]);
            EditorGUI.BeginProperty(controlRect, null, property);
            EditorGUI.BeginChangeCheck();
            num3 = EditorGUI.FloatField(controlRect, s_Styles.ScaleInLightmap, num3);
            if (EditorGUI.EndChangeCheck())
            {
                property.floatValue = Mathf.Max((float) (num3 / lightmapLODLevelScale), (float) 0f);
            }
            EditorGUI.EndProperty();
            return (LightmapVisualization.GetLightmapLODLevelScale(renderers[0]) * num3);
        }

        private void Maps()
        {
            GUI.changed = false;
            SerializedObject obj2 = new SerializedObject(LightmapEditorSettings.GetLightmapSettings());
            EditorGUILayout.PropertyField(obj2.FindProperty("m_LightProbes"), s_Styles.LightProbes, new GUILayoutOption[0]);
            obj2.ApplyModifiedProperties();
            GUILayout.Space(10f);
            LightmapData[] lightmaps = LightmapSettings.lightmaps;
            int length = Mathf.Clamp(EditorGUI.ArraySizeField(GUILayoutUtility.GetRect(100f, 100f, 16f, 16f, EditorStyles.numberField), s_Styles.MapsArraySize, LightmapSettings.lightmaps.Length, EditorStyles.numberField), 0, 0xfe);
            this.Compress();
            this.m_ScrollPositionMaps = GUILayout.BeginScrollView(this.m_ScrollPositionMaps, new GUILayoutOption[0]);
            for (int i = 0; i < lightmaps.Length; i++)
            {
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.FlexibleSpace();
                GUILayout.Label(i.ToString(), new GUILayoutOption[0]);
                GUILayout.Space(5f);
                lightmaps[i].lightmapFar = this.LightmapField(lightmaps[i].lightmapFar, i);
                GUILayout.Space(10f);
                lightmaps[i].lightmapNear = this.LightmapField(lightmaps[i].lightmapNear, i);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
            if (GUI.changed)
            {
                if (length != lightmaps.Length)
                {
                    LightmapData[] destinationArray = Array.CreateInstance(typeof(LightmapData), length) as LightmapData[];
                    Array.Copy(lightmaps, destinationArray, Mathf.Min(lightmaps.Length, length));
                    for (int j = lightmaps.Length; j < length; j++)
                    {
                        destinationArray[j] = new LightmapData();
                    }
                    LightmapSettings.lightmaps = destinationArray;
                }
                else
                {
                    LightmapSettings.lightmaps = lightmaps;
                }
                RepaintSceneAndGameViews();
            }
        }

        private void MarkEndTime()
        {
            if ((this.m_BakeStartTime < 0f) || ((Time.realtimeSinceStartup - this.m_BakeStartTime) < 0f))
            {
                this.m_LastBakeTimeString = string.Empty;
            }
            else
            {
                try
                {
                    TimeSpan span = TimeSpan.FromSeconds((double) (Time.realtimeSinceStartup - this.m_BakeStartTime));
                    string[] textArray1 = new string[] { "Last bake took ", (span.Days <= 0) ? string.Empty : (span.Days + "."), ((span.Hours <= 0) && (span.Days <= 0)) ? string.Empty : (span.Hours.ToString("00") + ":"), span.Minutes.ToString("00"), ":", span.Seconds.ToString("00") };
                    this.m_LastBakeTimeString = string.Concat(textArray1);
                }
                catch (System.Exception)
                {
                    this.m_LastBakeTimeString = string.Empty;
                }
            }
        }

        private void MarkStartTime()
        {
            this.m_BakeStartTime = Time.realtimeSinceStartup;
        }

        private void MenuSelectLightmapUsers(Rect rect, int lightmapIndex)
        {
            if ((Event.current.type == EventType.ContextClick) && rect.Contains(Event.current.mousePosition))
            {
                string[] texts = new string[] { "Select Lightmap Users" };
                Rect position = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 1f, 1f);
                EditorUtility.DisplayCustomMenu(position, EditorGUIUtility.TempContent(texts), -1, new EditorUtility.SelectMenuItemFunction(this.SelectLightmapUsers), lightmapIndex);
                Event.current.Use();
            }
        }

        private void ModeToggle()
        {
            this.m_Mode = (Mode) GUILayout.Toolbar((int) this.m_Mode, s_Styles.ModeToggles, "LargeButton", new GUILayoutOption[0]);
        }

        private void ObjectSettings()
        {
            GameObject[] objArray;
            bool flag = true;
            System.Type[] types = new System.Type[] { typeof(Light), typeof(UnityEngine.Renderer), typeof(Terrain) };
            SceneModeUtility.SearchBar(types);
            EditorGUILayout.Space();
            System.Type[] typeArray2 = new System.Type[] { typeof(MeshRenderer), typeof(SkinnedMeshRenderer) };
            UnityEngine.Renderer[] selectedObjectsOfType = SceneModeUtility.GetSelectedObjectsOfType<UnityEngine.Renderer>(out objArray, typeArray2);
            if (objArray.Length > 0)
            {
                flag = false;
                EditorGUILayout.MultiSelectionObjectTitleBar(selectedObjectsOfType);
                SerializedObject obj2 = new SerializedObject(objArray);
                if (!SceneModeUtility.StaticFlagField("Lightmap Static", obj2.FindProperty("m_StaticEditorFlags"), 1))
                {
                    GUI.enabled = false;
                }
                SerializedObject so = new SerializedObject(selectedObjectsOfType);
                float num = this.LightmapScaleGUI(so, selectedObjectsOfType);
                float f = !(selectedObjectsOfType[0] is MeshRenderer) ? InternalMeshUtil.GetCachedSkinnedMeshSurfaceArea(selectedObjectsOfType[0] as SkinnedMeshRenderer) : InternalMeshUtil.GetCachedMeshSurfaceArea(selectedObjectsOfType[0] as MeshRenderer);
                float num3 = (Mathf.Sqrt(f) * LightmapEditorSettings.resolution) * num;
                float num4 = Math.Min(LightmapEditorSettings.maxAtlasWidth, LightmapEditorSettings.maxAtlasHeight);
                this.m_ShowClampedSize.target = num3 > num4;
                if (EditorGUILayout.BeginFadeGroup(this.m_ShowClampedSize.faded))
                {
                    GUILayout.Label(s_Styles.ClampedSize, EditorStyles.helpBox, new GUILayoutOption[0]);
                }
                EditorGUILayout.EndFadeGroup();
                this.m_ShowAtlas = EditorGUILayout.Foldout(this.m_ShowAtlas, s_Styles.Atlas);
                if (this.m_ShowAtlas)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(so.FindProperty("m_LightmapIndex"), s_Styles.AtlasIndex, new GUILayoutOption[0]);
                    EditorGUILayout.PropertyField(so.FindProperty("m_LightmapTilingOffset.x"), s_Styles.AtlasTilingX, new GUILayoutOption[0]);
                    EditorGUILayout.PropertyField(so.FindProperty("m_LightmapTilingOffset.y"), s_Styles.AtlasTilingY, new GUILayoutOption[0]);
                    EditorGUILayout.PropertyField(so.FindProperty("m_LightmapTilingOffset.z"), s_Styles.AtlasOffsetX, new GUILayoutOption[0]);
                    EditorGUILayout.PropertyField(so.FindProperty("m_LightmapTilingOffset.w"), s_Styles.AtlasOffsetY, new GUILayoutOption[0]);
                    EditorGUI.indentLevel--;
                }
                if (!this.HasNormals(selectedObjectsOfType[0]))
                {
                    EditorGUILayout.HelpBox(s_Styles.NoNormalsNoLightmapping.text, MessageType.Warning);
                }
                so.ApplyModifiedProperties();
                GUI.enabled = true;
                GUILayout.Space(10f);
            }
            Light[] source = SceneModeUtility.GetSelectedObjectsOfType<Light>(out objArray, new System.Type[0]);
            if (objArray.Length > 0)
            {
                flag = false;
                EditorGUILayout.MultiSelectionObjectTitleBar(source.ToArray<Light>());
                SerializedObject obj4 = new SerializedObject(source.ToArray<Light>());
                bool flag2 = !obj4.FindProperty("m_Type").hasMultipleDifferentValues && (source[0].type == LightType.Area);
                if (this.m_LastAmountOfLights > 0)
                {
                    this.m_ShowAreaLight.target = flag2;
                }
                else
                {
                    this.m_ShowAreaLight.value = flag2;
                }
                SerializedProperty property = obj4.FindProperty("m_Lightmapping");
                if (EditorGUILayout.BeginFadeGroup(1f - this.m_ShowAreaLight.faded))
                {
                    EditorGUILayout.PropertyField(property, new GUILayoutOption[0]);
                }
                EditorGUILayout.EndFadeGroup();
                if (property.intValue == 0)
                {
                    GUI.enabled = false;
                }
                EditorGUILayout.PropertyField(obj4.FindProperty("m_Color"), new GUILayoutOption[0]);
                EditorGUILayout.Slider(obj4.FindProperty("m_Intensity"), 0f, 8f, new GUILayoutOption[0]);
                if (InternalEditorUtility.HasPro())
                {
                    EditorGUILayout.PropertyField(obj4.FindProperty("m_IndirectIntensity"), s_Styles.LightIndirectIntensity, new GUILayoutOption[0]);
                }
                EditorGUILayout.IntPopup(obj4.FindProperty("m_Shadows.m_Type"), this.kShadowTypeStrings, this.kShadowTypeValues, s_Styles.LightShadows, new GUILayoutOption[0]);
                this.m_ShowShadowOptions.target = source[0].shadows != LightShadows.None;
                if (EditorGUILayout.BeginFadeGroup(this.m_ShowShadowOptions.faded))
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(obj4.FindProperty("m_ShadowSamples"), s_Styles.LightShadowSamples, new GUILayoutOption[0]);
                    this.m_ShowShadowAngleOrSize.target = source[0].type != LightType.Area;
                    if (EditorGUILayout.BeginFadeGroup(this.m_ShowShadowAngleOrSize.faded))
                    {
                        if (source[0].type == LightType.Directional)
                        {
                            EditorGUILayout.Slider(obj4.FindProperty("m_ShadowAngle"), 0f, 90f, s_Styles.LightShadowAngle, new GUILayoutOption[0]);
                        }
                        else
                        {
                            EditorGUILayout.Slider(obj4.FindProperty("m_ShadowRadius"), 0f, 2f, s_Styles.LightShadowRadius, new GUILayoutOption[0]);
                        }
                    }
                    EditorGUILayout.EndFadeGroup();
                    EditorGUI.indentLevel--;
                }
                EditorGUILayout.EndFadeGroup();
                obj4.ApplyModifiedProperties();
                GUI.enabled = true;
                GUILayout.Space(10f);
            }
            this.m_LastAmountOfLights = source.Length;
            Terrain[] objects = SceneModeUtility.GetSelectedObjectsOfType<Terrain>(out objArray, new System.Type[0]);
            if (objArray.Length > 0)
            {
                flag = false;
                EditorGUILayout.MultiSelectionObjectTitleBar(objects);
                SerializedObject obj5 = new SerializedObject(objArray);
                if (!SceneModeUtility.StaticFlagField("Lightmap Static", obj5.FindProperty("m_StaticEditorFlags"), 1))
                {
                    GUI.enabled = false;
                }
                SerializedObject obj6 = new SerializedObject(objects.ToArray<Terrain>());
                SerializedProperty property3 = obj6.FindProperty("m_LightmapSize");
                bool flag3 = false;
                int intValue = property3.intValue;
                EditorGUILayout.IntPopup(property3, this.kTerrainLightmapSizeStrings, this.kTerrainLightmapSizeValues, s_Styles.TerrainLightmapSize, new GUILayoutOption[0]);
                flag3 |= intValue != property3.intValue;
                this.m_ShowAtlas = EditorGUILayout.Foldout(this.m_ShowAtlas, s_Styles.Atlas);
                if (this.m_ShowAtlas)
                {
                    EditorGUI.indentLevel++;
                    SerializedProperty property4 = obj6.FindProperty("m_LightmapIndex");
                    int num6 = property4.intValue;
                    EditorGUILayout.PropertyField(property4, s_Styles.AtlasIndex, new GUILayoutOption[0]);
                    flag3 |= num6 != property4.intValue;
                    EditorGUI.indentLevel--;
                }
                obj6.ApplyModifiedProperties();
                if (flag3)
                {
                    foreach (Terrain terrain in objects)
                    {
                        if (terrain != null)
                        {
                            terrain.Flush();
                        }
                    }
                }
                GUI.enabled = true;
                GUILayout.Space(10f);
            }
            if (flag)
            {
                GUILayout.Label(s_Styles.EmptySelection, EditorStyles.helpBox, new GUILayoutOption[0]);
            }
        }

        private void OnBecameInvisible()
        {
            s_IsVisible = false;
            LightmapVisualization.enabled = false;
            LightmapVisualization.showLightProbes = false;
            this.m_OldQualitySettingsShadowDistance = QualitySettings.shadowDistance;
            SceneView.onSceneGUIDelegate = (SceneView.OnSceneFunc) Delegate.Remove(SceneView.onSceneGUIDelegate, new SceneView.OnSceneFunc(this.OnSceneViewGUI));
            RepaintSceneAndGameViews();
        }

        private void OnBecameVisible()
        {
            if (!s_IsVisible)
            {
                s_IsVisible = true;
                LightmapVisualization.enabled = true;
                LightmapVisualization.showLightProbes = true;
                if (this.m_OldQualitySettingsShadowDistance != QualitySettings.shadowDistance)
                {
                    this.m_ShadowDistance = QualitySettings.shadowDistance;
                    this.m_OldQualitySettingsShadowDistance = this.m_ShadowDistance;
                }
                LightmapVisualization.shadowDistance = this.m_ShadowDistance;
                SceneView.onSceneGUIDelegate = (SceneView.OnSceneFunc) Delegate.Combine(SceneView.onSceneGUIDelegate, new SceneView.OnSceneFunc(this.OnSceneViewGUI));
                RepaintSceneAndGameViews();
            }
        }

        private void OnDidOpenScene()
        {
        }

        private void OnDisable()
        {
            s_LightmappingWindow = null;
            EditorApplication.searchChanged = (EditorApplication.CallbackFunction) Delegate.Remove(EditorApplication.searchChanged, new EditorApplication.CallbackFunction(this.Repaint));
        }

        private void OnEnable()
        {
            s_LightmappingWindow = this;
            this.m_ShowDualOptions.value = LightmapSettings.lightmapsMode == LightmapsMode.Dual;
            this.m_ShowFinalGather.value = (LightmapEditorSettings.bounces > 0) && InternalEditorUtility.HasPro();
            this.m_ShowShadowOptions.value = true;
            this.m_ShowShadowAngleOrSize.value = true;
            this.m_ShowAO.value = LightmapEditorSettings.aoAmount > 0f;
            this.m_ShowClampedSize.value = false;
            this.m_ShowColorSpaceWarning.value = colorSpaceWarningValue;
            this.m_ShowAreaLight.value = false;
            this.m_Anims.Add(this.m_ShowDualOptions);
            this.m_Anims.Add(this.m_ShowFinalGather);
            this.m_Anims.Add(this.m_ShowShadowOptions);
            this.m_Anims.Add(this.m_ShowShadowAngleOrSize);
            this.m_Anims.Add(this.m_ShowAO);
            this.m_Anims.Add(this.m_ShowClampedSize);
            this.m_Anims.Add(this.m_ShowColorSpaceWarning);
            this.m_Anims.Add(this.m_ShowAreaLight);
            base.autoRepaintOnSceneChange = true;
            this.m_PreviewResizer.Init("LightmappingPreview");
            EditorApplication.searchChanged = (EditorApplication.CallbackFunction) Delegate.Combine(EditorApplication.searchChanged, new EditorApplication.CallbackFunction(this.Repaint));
            base.Repaint();
        }

        private void OnGUI()
        {
            if (this.m_Anims.callback == null)
            {
                this.m_Anims.callback = new AnimValueManager.Callback(this.Repaint);
            }
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }
            EditorGUIUtility.LookLikeControls(130f);
            EditorGUILayout.Space();
            this.ModeToggle();
            EditorGUILayout.Space();
            this.m_ShowColorSpaceWarning.target = colorSpaceWarningValue;
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowColorSpaceWarning.faded))
            {
                EditorGUILayout.HelpBox(EditorGUIUtility.TextContent("LightEditor.WrongColorSpaceWarning").text, MessageType.Warning);
            }
            EditorGUILayout.EndFadeGroup();
            this.m_ScrollPosition = EditorGUILayout.BeginScrollView(this.m_ScrollPosition, new GUILayoutOption[0]);
            switch (this.m_Mode)
            {
                case Mode.ObjectSettings:
                    this.ObjectSettings();
                    break;

                case Mode.BakeSettings:
                    this.BakeSettings();
                    break;

                case Mode.Maps:
                    this.Maps();
                    break;
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.Space();
            if (this.m_ProbePositionsChanged && (Event.current.type == EventType.Layout))
            {
                int[] numArray;
                Vector3[] vectorArray;
                LightProbeGroupEditor.TetrahedralizeSceneProbes(out vectorArray, out numArray);
                this.m_IncorrectProbePositions = (vectorArray.Length > 0) && (numArray.Length == 0);
                this.m_ProbePositionsChanged = false;
            }
            if (this.m_IncorrectProbePositions)
            {
                EditorGUILayout.HelpBox(s_Styles.IncorrectLightProbePositions.text, MessageType.Warning);
            }
            GUI.enabled = !EditorApplication.isPlayingOrWillChangePlaymode;
            this.Buttons();
            GUI.enabled = true;
            EditorGUILayout.Space();
            this.Summary();
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Height(17f) };
            Rect position = EditorGUILayout.BeginHorizontal(GUIContent.none, "preToolbar", options);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            GUI.Label(position, "Preview", "preToolbar2");
            float height = this.m_PreviewResizer.ResizeHandle(base.position, 100f, 250f, 17f);
            if (height > 0f)
            {
                this.Lightmaps(new Rect(0f, base.position.height - height, base.position.width, height));
            }
        }

        public void OnSceneViewGUI(SceneView sceneView)
        {
            if (s_IsVisible)
            {
                SceneViewOverlay.Window(new GUIContent("Lightmap Display"), new SceneViewOverlay.WindowFunction(this.DisplayControls), 200, SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget);
            }
        }

        private void OnSelectionChange()
        {
            this.UpdateLightmapSelection();
            if ((this.m_Mode == Mode.ObjectSettings) || (this.m_Mode == Mode.Maps))
            {
                base.Repaint();
            }
        }

        public static void ProbePositionsChanged()
        {
            if (s_LightmappingWindow != null)
            {
                s_LightmappingWindow.m_ProbePositionsChanged = true;
            }
        }

        private static void RepaintSceneAndGameViews()
        {
            SceneView.RepaintAll();
            GameView.RepaintAll();
        }

        private void SelectLightmapUsers(object userData, string[] options, int selected)
        {
            int num = (int) userData;
            ArrayList list = new ArrayList();
            MeshRenderer[] rendererArray = UnityEngine.Object.FindObjectsOfType(typeof(MeshRenderer)) as MeshRenderer[];
            foreach (MeshRenderer renderer in rendererArray)
            {
                if ((renderer != null) && (renderer.lightmapIndex == num))
                {
                    list.Add(renderer.gameObject);
                }
            }
            Terrain[] terrainArray = UnityEngine.Object.FindObjectsOfType(typeof(Terrain)) as Terrain[];
            foreach (Terrain terrain in terrainArray)
            {
                if ((terrain != null) && (terrain.lightmapIndex == num))
                {
                    list.Add(terrain.gameObject);
                }
            }
            Selection.objects = list.ToArray(typeof(UnityEngine.Object)) as UnityEngine.Object[];
        }

        private void Summary()
        {
            GUILayout.BeginVertical(EditorStyles.helpBox, new GUILayoutOption[0]);
            if (this.m_LastBakeTimeString != string.Empty)
            {
                GUILayout.Label(this.m_LastBakeTimeString, s_Styles.labelStyle, new GUILayoutOption[0]);
            }
            int bytes = 0;
            int num2 = 0;
            Dictionary<Vector2, int> dictionary = new Dictionary<Vector2, int>();
            bool flag = false;
            foreach (LightmapData data in LightmapSettings.lightmaps)
            {
                if (data.lightmapFar != null)
                {
                    num2++;
                    Vector2 key = new Vector2((float) data.lightmapFar.width, (float) data.lightmapFar.height);
                    if (dictionary.ContainsKey(key))
                    {
                        Dictionary<Vector2, int> dictionary2;
                        Vector2 vector2;
                        int num4 = dictionary2[vector2];
                        (dictionary2 = dictionary)[vector2 = key] = num4 + 1;
                    }
                    else
                    {
                        dictionary.Add(key, 1);
                    }
                    bytes += TextureUtil.GetRuntimeMemorySize(data.lightmapFar);
                    if (data.lightmapNear != null)
                    {
                        bytes += TextureUtil.GetRuntimeMemorySize(data.lightmapNear);
                        flag = true;
                    }
                }
            }
            object[] objArray1 = new object[] { num2, !flag ? " single" : " dual", " lightmap", (num2 != 1) ? "s" : string.Empty };
            string str = string.Concat(objArray1);
            bool flag2 = true;
            foreach (KeyValuePair<Vector2, int> pair in dictionary)
            {
                str = str + (!flag2 ? ", " : ": ");
                flag2 = false;
                if (pair.Value > 1)
                {
                    str = str + pair.Value + "x";
                }
                string str2 = str;
                object[] objArray2 = new object[] { str2, pair.Key.x, "x", pair.Key.y, "px" };
                str = string.Concat(objArray2);
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Label(str + " ", s_Styles.labelStyle, new GUILayoutOption[0]);
            GUILayout.Label("Color space ", s_Styles.labelStyle, new GUILayoutOption[0]);
            GUILayout.EndVertical();
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Label(EditorUtility.FormatBytes(bytes), s_Styles.labelStyle, new GUILayoutOption[0]);
            GUILayout.Label((num2 != 0) ? (string.Empty + LightmapSettings.bakedColorSpace) : "No Lightmaps", s_Styles.labelStyle, new GUILayoutOption[0]);
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }

        private void UpdateLightmapSelection()
        {
            MeshRenderer renderer;
            Terrain terrain = null;
            if ((Selection.activeGameObject == null) || (((renderer = Selection.activeGameObject.GetComponent<MeshRenderer>()) == null) && ((terrain = Selection.activeGameObject.GetComponent<Terrain>()) == null)))
            {
                this.m_SelectedLightmap = -1;
            }
            else
            {
                this.m_SelectedLightmap = (renderer == null) ? terrain.lightmapIndex : renderer.lightmapIndex;
            }
        }

        private BakeMode bakeMode
        {
            get
            {
                return (BakeMode) EditorPrefs.GetInt("LightmapEditor.BakeMode", 0);
            }
            set
            {
                EditorPrefs.SetInt("LightmapEditor.BakeMode", (int) value);
            }
        }

        private static bool colorSpaceWarningValue
        {
            get
            {
                return ((LightmapSettings.bakedColorSpace != QualitySettings.desiredColorSpace) && (LightmapSettings.lightmaps.Length > 0));
            }
        }

        private enum BakeMode
        {
            BakeScene,
            BakeSelected,
            BakeProbes
        }

        private enum Mode
        {
            ObjectSettings,
            BakeSettings,
            Maps
        }

        private class Styles
        {
            public GUIContent AO = EditorGUIUtility.TextContent("LightmapEditor.AO");
            public GUIContent AOContrast = EditorGUIUtility.TextContent("LightmapEditor.AOContrast");
            public GUIContent AOMaxDistance = EditorGUIUtility.TextContent("LightmapEditor.AOMaxDistance");
            public GUIContent Atlas = EditorGUIUtility.TextContent("LightmapEditor.Atlas");
            public GUIContent AtlasIndex = EditorGUIUtility.TextContent("LightmapEditor.AtlasIndex");
            public GUIContent AtlasOffsetX = EditorGUIUtility.TextContent("LightmapEditor.AtlasOffsetX");
            public GUIContent AtlasOffsetY = EditorGUIUtility.TextContent("LightmapEditor.AtlasOffsetY");
            public GUIContent AtlasTilingX = EditorGUIUtility.TextContent("LightmapEditor.AtlasTilingX");
            public GUIContent AtlasTilingY = EditorGUIUtility.TextContent("LightmapEditor.AtlasTilingY");
            public GUIContent BounceBoost = EditorGUIUtility.TextContent("LightmapEditor.BounceBoost");
            public GUIContent BounceIntensity = EditorGUIUtility.TextContent("LightmapEditor.BounceIntensity");
            public GUIContent Bounces = EditorGUIUtility.TextContent("LightmapEditor.Bounces");
            public GUIContent ClampedSize = EditorGUIUtility.TextContent("LightmapEditor.ClampedSize");
            public GUIContent DirectionalLightmapsProOnly = EditorGUIUtility.TextContent("LightmapEditor.DirectionalLightmapsProOnly");
            public GUIStyle dropDownButton = "DropDownButton";
            public GUIContent EmptySelection = EditorGUIUtility.TextContent("LightmapEditor.EmptySelection");
            public GUIContent FinalGatherContrastThreshold = EditorGUIUtility.TextContent("LightmapEditor.FinalGather.ContrastThreshold");
            public GUIContent FinalGatherGradientThreshold = EditorGUIUtility.TextContent("LightmapEditor.FinalGather.GradientThreshold");
            public GUIContent FinalGatherInterpolationPoints = EditorGUIUtility.TextContent("LightmapEditor.FinalGather.InterpolationPoints");
            public GUIContent FinalGatherRays = EditorGUIUtility.TextContent("LightmapEditor.FinalGather.Rays");
            public GUIContent IncorrectLightProbePositions = EditorGUIUtility.TextContent("LightmapEditor.IncorrectLightProbePositions");
            public GUIStyle labelStyle = EditorStyles.wordWrappedMiniLabel;
            public GUIContent LightIndirectIntensity = EditorGUIUtility.TextContent("LightmapEditor.Light.IndirectIntensity");
            public GUIContent LightProbes = EditorGUIUtility.TextContent("LightmapEditor.LightProbes");
            public GUIContent LightShadowAngle = EditorGUIUtility.TextContent("LightmapEditor.Light.ShadowAngle");
            public GUIContent LightShadowRadius = EditorGUIUtility.TextContent("LightmapEditor.Light.ShadowRadius");
            public GUIContent LightShadows = EditorGUIUtility.TextContent("LightmapEditor.Light.Shadows");
            public GUIContent LightShadowSamples = EditorGUIUtility.TextContent("LightmapEditor.Light.ShadowSamples");
            public GUIContent LockAtlas = EditorGUIUtility.TextContent("LightmapEditor.LockAtlas");
            public GUIContent LODSurfaceDistance = EditorGUIUtility.TextContent("LightmapEditor.LODSurfaceDistance");
            public GUIContent MapsArraySize = EditorGUIUtility.TextContent("LightmapEditor.MapsArraySize");
            public GUIContent Mode = EditorGUIUtility.TextContent("LightmapEditor.Mode");
            public GUIContent[] ModeToggles = new GUIContent[] { EditorGUIUtility.TextContent("LightmapEditor.ObjectSettings"), EditorGUIUtility.TextContent("LightmapEditor.BakeSettings"), EditorGUIUtility.TextContent("LightmapEditor.Maps") };
            public GUIContent NoNormalsNoLightmapping = EditorGUIUtility.TextContent("LightmapEditor.NoNormalsNoLightmapping");
            public GUIContent Padding = EditorGUIUtility.TextContent("LightmapEditor.Padding");
            public GUIContent Quality = EditorGUIUtility.TextContent("LightmapEditor.Quality");
            public GUIContent Resolution = EditorGUIUtility.TextContent("LightmapEditor.Resolution");
            public GUIContent ScaleInLightmap = EditorGUIUtility.TextContent("LightmapEditor.ScaleInLightmap");
            public GUIStyle selectedLightmapHighlight = "LightmapEditorSelectedHighlight";
            public GUIContent SkyLightColor = EditorGUIUtility.TextContent("LightmapEditor.SkyLightColor");
            public GUIContent SkyLightIntensity = EditorGUIUtility.TextContent("LightmapEditor.SkyLightIntensity");
            public GUIContent Static = EditorGUIUtility.TextContent("LightmapEditor.Static");
            public GUIContent TerrainLightmapSize = EditorGUIUtility.TextContent("LightmapEditor.Terrain.LightmapSize");
            public GUIContent TextureCompression = EditorGUIUtility.TextContent("LightmapEditor.TextureCompression");
            public GUIContent UseDualInForward = EditorGUIUtility.TextContent("LightmapEditor.UseDualInForward");
        }
    }
}

